class Solution {
public:
    void nextPermutation(vector<int>& nums) {
        
        if(nums.size() == 1) return;
        int small_index=-1, big_index=-1;
        
        for(int i=nums.size()-2; i>=0; i--){
            if(nums[i] < nums[i+1]){
                small_index = i;
                break;
            }
        }
        if(small_index != -1){
            for(int i=nums.size()-1; i>small_index; i--){
                if(nums[i] > nums[small_index]){
                    big_index = i;
                    break;
                }
            }
            swap(nums[small_index], nums[big_index]);
        }
        reverse(nums.begin()+small_index+1, nums.end());
    }
};